package com.dattplace.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	public static String dataToString(Date date ,String format){
		
		SimpleDateFormat sf =new SimpleDateFormat(format);
		return sf.format(date);
	}
	
	public static Date strToDate(String Date,String format ){
		SimpleDateFormat sf =new SimpleDateFormat(format);
		try {
			return sf.parse(Date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public static int getWeekOfDate(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		int dayForWeek = 0;
		if (c.get(Calendar.DAY_OF_WEEK) == 1) {
			dayForWeek = 7;
		} else {
			dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
		}
		return dayForWeek;
	}
	
	public static void main(String[] args) {
		System.out.println(getWeekOfDate(new Date()));
	}
}
